package studychinese.fragment;


import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hschinese.pronunciation.R;

import java.text.ParseException;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.qqtheme.framework.picker.DatePicker;
import cn.qqtheme.framework.util.ConvertUtils;
import studychinese.model.RegisterBean;
import studychinese.model.UserBean;
import studychinese.utils.TimeUtil;

/**
 * A simple {@link Fragment} subclass.
 */
public class NativeBirthdayFragment extends Fragment {


    @Bind(R.id.tv_native_titile)
    TextView tvNativeTitile;
    @Bind(R.id.rl_native_seletebirthday)
    RelativeLayout rl_native_seletebirthday;

    public static NativeBirthdayFragment newInstance(String title) {

        Bundle args = new Bundle();
        args.putString("title", title);
        NativeBirthdayFragment fragment = new NativeBirthdayFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_native_birthday, container, false);
        ButterKnife.bind(this, view);
        init();
        onYearMonthDayPicker();
        return view;
    }

    public void init() {

        /*OptionPicker picker = new OptionPicker(getActivity(), new String[]{
                "第一项", "第二项", "第三项","第四项","第五项"
        });
       *//* picker.setCanceledOnTouchOutside(false);
        picker.setDividerRatio(WheelView.DividerConfig.FILL);*//*

        picker.setSelectedIndex(1);
        picker.setCycleDisable(true);
        picker.setOffset(3);
       *//* picker.setDividerVisible(true);
        picker.setLineSpaceMultiplier(4);
        picker.setDividerColor(Color.WHITE);*//*
        picker.setTextSize(20);
        picker.setLineColor(Color.WHITE);

        picker.setTextColor(Color.WHITE,Color.WHITE);
        picker.setCycleDisable(false);
        picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
            @Override
            public void onOptionPicked(int index, String item) {
               // showToast();
                ToastUtils.showShort("index=" + index + ", item=" + item);
            }
        });

        //得到选择器视图，可内嵌到其他视图容器，不需要调用show方法
        View pickerContentView = picker.getContentView();
        rlNativeSeletelanguage.addView(pickerContentView);*/
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
    public void onYearMonthDayPicker() {
        final DatePicker picker = new DatePicker(getActivity());
        picker.setTopPadding(ConvertUtils.toPx(getActivity(), 10));
        picker.setRangeEnd(2111, 1, 11);
        picker.setRangeStart(1945, 1, 1);
        picker.setSelectedItem(2017, 10, 14);

        picker.setLabel("年","月","日");
        picker.setOffset(2);
        picker.setDividerVisible(true);
        picker.setLineSpaceMultiplier(4);
        picker.setDividerColor(Color.WHITE);
        picker.setTextSize(18);
        picker.setLineColor(Color.WHITE);
        picker.setTextColor(Color.WHITE,Color.WHITE);
        picker.setCycleDisable(false);
        picker.setDividerRatio(0);
        picker.setOnDatePickListener(new DatePicker.OnYearMonthDayPickListener() {

            @Override
            public void onDatePicked(String year, String month, String day) {

            }
        });

        picker.setOnWheelListener(new DatePicker.OnWheelListener() {
            @Override
            public void onYearWheeled(int index, String year) {
                setTime(year + "-" + picker.getSelectedMonth() + "-" + picker.getSelectedDay());
            }

            @Override
            public void onMonthWheeled(int index, String month) {
                setTime(picker.getSelectedYear() + "-" + month + "-" + picker.getSelectedDay());

            }

            @Override
            public void onDayWheeled(int index, String day) {

                    setTime(picker.getSelectedYear() + "-" + picker.getSelectedMonth() + "-" + day);

            }
        });
        View pickerContentView = picker.getContentView();
        rl_native_seletebirthday.addView(pickerContentView);
        setTime("2017-10-14");


    }

    private void setTime(String time){



            try {
                if(!"".equals(time)){
                    long data = 0;
                    data = TimeUtil.StringToTime(time);
                    RegisterBean.DataBean infor = UserBean.getInfor();
                    if(infor!=null){
                        infor.setUser_age(data+"");
                    }
                    UserBean.putUserBean(infor);
                }

            } catch (ParseException e) {
                e.printStackTrace();
            }



    }
}
